import {Injectable} from '@angular/core';
import * as API from "@api/index";
import {HttpService} from "@core/http/http.service";
import {Observable} from "rxjs/Observable";

import {Response} from "@angular/http";
import {
  BodyDataLatestVO,
  ClassForStudentVO, CommonPageVo,
  SNSResult, StudentBodyDataVO, StudentTestLastScoreVO,
  StudentTestScoreDetailVO, TrainAgeDictionarie, StudentTestScoreRadarChartVO,
  TrainSchoolCourseListScheduleVo,
  TrainStudentTestScoreDetail,
  TrainStudent,
  TrainTeacherVO, StudentTestScoreLineChartVO, StudentTestAbilityScoreChartVO, TrainTestItemScoreDetailVO,
  StudentTestLastScoreWrapVO
} from "@interface/index";
import {ToolsService} from "@shared/service/tools/tools.service";


@Injectable()
export class ParentService {

  constructor(
    private httpService: HttpService,
    private tools: ToolsService
  ) {
  }

  /**
   * @author guoqs1331
   * @time 2018/1/26
   * @description 获取家长名下孩子
   */
  findSutdent(orgUserId: string): Observable<SNSResult<TrainStudent[]>> {
    const url = `${API.FIND_STUDENT}?orgUserId=${orgUserId}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/1/26
   * @description 根据学生Id获取班级(家长)
   */
  findClassRoomByStudId(studentId: string): Observable<SNSResult<ClassForStudentVO[]>> {
    const url = `${API.FIND_CLASSROOM_BY_STUDID}?studentId=${studentId}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/2/28
   * @description 查询课时点评未读数
   */
  findUnreadCount(studentId: number, classId: number): Observable<SNSResult<number>> {
    const url = `${API.FIND_UNREAD_COUNT}?studentId=${studentId}&classId=${classId}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @desc 查询学生详情
   * @author ouxh
   * @time 2018/1/26
   * @description 根据学生Id获取班级(家长)
   */
  findStudentInfo(params): Observable<SNSResult<TrainStudent>> {
    const query = this.tools.param(params);
    const url = `${API.STUDENT}?${query}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @desc 查询学生详情
   * @author ouxh
   * @time 2018/1/26
   * @description 根据学生Id获取班级(家长)
   */
  updateStudentInfo(params): Observable<SNSResult<TrainStudent>> {
    const url = `${API.STUDENT}`;
    return this.httpService.putUrlencode(url, params).map((res: Response) => res.json());
  }

  /**
   * @desc 查询学生课程表
   * @author ouxh
   * @time 2018/1/26
   * @description 根据学生Id获取班级(家长)
   */
  findScheduleList(params): Observable<SNSResult<TrainSchoolCourseListScheduleVo[]>> {
    const query = this.tools.param(params);
    const url = `${API.COURSE_SCHEDULE_LIST}?${query}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/1/29
   * @description 查询教练信息
   */
  trainCourseTeacherInfoByClassId(classId: number): Observable<SNSResult<TrainTeacherVO[]>> {
    const url = `${API.COURSE_TEACHER_INFO_BY_CLASSID}?classId=${classId}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @description 获取用户身体数据
   * @author @chenwh576
   * @param {string} orgUserId
   * @param {number} studentId
   * @return {Observable<SNSResult<StudentBodyDataVO[]>>}
   */
  fetchStudentBodyDate(orgUserId: string, studentId: number): Observable<SNSResult<StudentBodyDataVO[]>> {
    const url = `${API.TRAIN_STUDENT_BODY_DATA}?orgUserId=${orgUserId}&studentId=${studentId}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/3/29
   * @description 学员最新身体数据
   */
  studentBodyDataLatest(orgUserId: string, studentId: number): Observable<SNSResult<BodyDataLatestVO[]>> {
    const url = `${API.TRAIN_STUDENTBODYDATA_LAST}?orgUserId=${orgUserId}&studentId=${studentId}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/4/12
   * @description 获取学生成绩七星雷达图
   */
  studentScoreRadarChart(studentId: number): Observable<SNSResult<StudentTestScoreRadarChartVO>> {
    const url = `${API.STUDENT_SCORE_RADAR_CHART}?studentId=${studentId}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/4/15
   * @description 查询学生最后一次查询成绩
   */
  getLastScore(studentId: number): Observable<SNSResult<StudentTestLastScoreVO>> {
    const url = `${API.GET_LAST_SCORE}?studentId=${studentId}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/4/15
   * @description 能力成长记录
   */
  getStudentAbilityRecord(studentId: number): Observable<SNSResult<StudentTestLastScoreVO[]>> {
    const url = `${API.STUDENT_ABILITY_RECORD}?studentId=${studentId}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/4/15
   * @description //根据学生id、测试维度id分页查询学生能力值变化列表
   */
  studentAbilityScoreList(params) {
    const url = API.ABILITY_SCORE_LIST + "?" + this.tools.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/4/15
   * @description //根据学生id，测试模块id,分页查询能力值变化柱状图
   */
  studentAbilityScoreChart(params): Observable<SNSResult<CommonPageVo<StudentTestAbilityScoreChartVO>>> {
    const url = API.ABILITY_SCORE_CHART + "?" + this.tools.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/4/15
   * @description 根据测试能力项查看评分标准
   */
  standard(params) {
    const url = API.STANDARD + "?" + this.tools.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/4/15
   * @description 获取学员测试项及成绩
   */
  itemScoreInfo(params): Observable<SNSResult<TrainTestItemScoreDetailVO>> {
    const url = API.ITEM_SCORE_INFO + "?" + this.tools.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @description 查询学生 历史成绩
   * @author zhupw1360
   * @date 2018-04-16
   * @param
   */
  getStudentScoreHistory(params): Observable<SNSResult<CommonPageVo<TrainStudentTestScoreDetail>>> {
    const url = API.GET_STUDENT_SCORE_METHOD + '?' + this.tools.param(params);
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @description 根据学生id,年龄组id，测试模块id，测试方法id查询测试成绩详情
   * @author zhupw1360
   * @date 2018-04-16
   * @param
   */
  getStudentScoreDetail(params): Observable<SNSResult<StudentTestScoreDetailVO>> {
    const url = API.GET_STUDENT_SCORE_DETAIL + '?' + this.tools.param(params);
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/4/16
   * @description 获取测试年龄组
   */
  getAgeDicts(): Observable<SNSResult<TrainAgeDictionarie[]>> {
    const url = API.GET_AGE_DICTS;
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/4/17
   * @description 查询学生查询最近七次测试成绩折线图
   */
  studentTestScoreLineChart(param): Observable<SNSResult<StudentTestScoreLineChartVO>> {
    const url = API.TEST_SCORE_LINE_CHART + '?' + this.tools.param(param);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/4/19
   * @description 以组为单位获取最后一次成绩
   */
  getLastScoreGroup(param): Observable<SNSResult<StudentTestLastScoreWrapVO[]>> {
    const url = API.GET_LAST_SCORE_GROUP + '?' + this.tools.param(param);
    return this.httpService.get(url).map((res) => res.json());
  }
}
